#ifndef COM_DICT_H_
#define COM_DICT_H_

#define MAX_COMMAND_LENGTH 20
#define MAX_COMMAND_DESC_LENGTH 50
#define MAX_COMMAND_HELP_LENGTH 1024

/* Command Dictionary Record - Maps command name to execution function */
typedef struct {
	char name[MAX_COMMAND_LENGTH];
	char desc[MAX_COMMAND_DESC_LENGTH];
	char help[MAX_COMMAND_HELP_LENGTH];
	int (*exec_func)(char*);
} command_rec;

/* Command Dictionary Linked List Node - Stores a command record */
typedef struct {
	command_rec *command;
	struct command_node *next;
	struct command_node *prev;
} command_node;

/* Command Dictionary - Linked list structure maps command name strings to descriptions and executable functions */
typedef struct {
	command_node *head;
	int total_commands;
} command_dict;

//Singleton command dictionary. Global variable
static command_dict *gbl_command_dict;

/* Initialize dictionary data structure and insert built-in commands */
int init_command_dict();

/* Initialize dictionary data structure and insert built-in commands */
void free_com_dict();

/* Add a new command (maps a name to a description/function)*/
/* Note: All commands execute a function that returns an integer code and accepts a single argument string */
void add_command(char *name, char *desc, char *help, int (*exec_func)(char*));

/* Finds a command based on its name. Returns a null pointer if no result, the command record if successful. */
command_rec* get_command(char *name);

/* Lists all commands in the dicitionary */
void list_commands();

/* Converts a command record into a string representation based on the max command/description length */
char* command_rec_to_str(command_rec *command);

#endif /* COM_DICT_H_ */